
/* 
@title: get_the_gift
@description: "Get the Gift" is a two-player game. One player controls a dog and the other controls a cat, and each must navigate through levels to reach their respective goals. The game requires cooperation and strategy to overcome obstacles and win.
@author: Annaleah Sauceda
@tags: []
@addedOn: 2023-08-08
@img: ""
*/


const upSe  = tune`
37.5: F4^37.5,
37.5: G4^37.5,
37.5: A4^37.5,
1087.5`
 const downSe  = tune`
37.5: A4~37.5,
37.5: G4~37.5,
37.5: F4~37.5,
1087.5`
 const rightSe  = tune`
37.5: G4^37.5,
37.5: A4^37.5,
1125`
  const leftSe  = tune`
37.5: A4^37.5,
37.5: G4^37.5,
1125`
    const enemy = 'e'
    const player = 'p'
    const wall = 'w'
    const goal = 'g'
    const sky = 's'


setLegend(
    [enemy, bitmap`
..00.3...3..00..
..0033...33000..
..000000000000..
..000000000000..
..006300006300..
..003600003600..
..000000000000..
..000003300000..
..30000000000.3.
..3333666633333.
..3333099003333.
..3.3.000000303.
......000000000.
......0.0...0.0.
......0.0...0.0.
................`],
	[player, bitmap`
....333.333.....
.......1........
......55H.......
...44444HH......
..64444444466...
..66666666666...
....6066606.....
....8666668.....
....6663666.....
.....7977....6..
.....666666666..
.....66666666...
......6666666...
......6.F..6F...
.....66FF.66F...
................`],
    [wall, bitmap`
................
................
................
................
........222.....
....2222222.....
..22222222222...
..22222222222...
..2222222222....
......22........
................
................
................
................
................
................`],
    [goal, bitmap`
................
.....33....3....
2...3333.333...2
22....33333...22
2221111131111122
2221222232222122
2221222232222122
2221222232222122
.221222232222122
..2333333333332.
...12222322221..
...12222322221..
...12222322221..
...11111311111..
................
................`],
    [sky, bitmap`
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777
7777777777777777`],
  
);

setBackground(sky)


let level = 0; 
const levels = [
  map`
.................
.................
........g........
.................
.................
.................
..e...........p..
.................
.................
.................
.................
.................
.................`,
  map`
..w......
g.....ww.
....w....
.w......p
...w..ww.`,
  map`
.....g.....
.w.we...ww.
.....www...
.w.w.....ww
..ww..www..
.....p.....`,
  map`
.g.........
..www.we...
.........w.
.w..wp...w.
.ww.w...w..
...........`,
  map`
..e........
.ww........
.......pwww
....www....
.......www.
..........g`,
  map`
w.w......w.
.w......ww.
..e..w..w..
gww...w....
.ww......p.
w.w.....www`,
  map`
gw.........
.w.ew..w...
.w.ww..w...
...w...w.w.
...w.....wp
...........`,
  map`
e.w........
...w....w.w
g....w.....
...w..w...p
.....w.....
.w.....w...`,
];


const currentLevel = levels[level];
setMap(currentLevel);


setSolids([ wall,player ]),
 

setPushables({
	[ player ]: []
})

onInput("s", () => {
	getFirst(player).y += 1
  playTune(downSe)
})

onInput("w", () => {
	getFirst(player).y -= 1
  playTune(upSe)
})

onInput("a", () => {
	getFirst(player).x -= 1
  playTune(leftSe)
})

onInput("d", () => {
	getFirst(player).x += 1
  playTune(rightSe)
})

onInput("k", () => {
	getFirst(enemy).y += 1
  playTune(downSe)
})

onInput("i", () => {
	getFirst(enemy).y -= 1
  playTune(upSe)
})

onInput("j", () => {
	getFirst(enemy).x -= 1
  playTune(leftSe)
})

onInput("l", () => {
	getFirst(enemy).x += 1
  playTune(rightSe)
})


const ogMusic = tune`
201.34228187919464,
201.34228187919464: G4^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: F4~201.34228187919464,
201.34228187919464: E4/201.34228187919464 + A4~201.34228187919464,
201.34228187919464: C4-201.34228187919464,
201.34228187919464: A4^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: G4~201.34228187919464,
201.34228187919464: F4/201.34228187919464 + B4~201.34228187919464,
201.34228187919464: C4-201.34228187919464,
201.34228187919464: B4^201.34228187919464,
201.34228187919464: C5~201.34228187919464 + C4-201.34228187919464,
201.34228187919464: D5/201.34228187919464 + F5~201.34228187919464,
201.34228187919464,
201.34228187919464: A4^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: G4~201.34228187919464 + C4-201.34228187919464 + C5~201.34228187919464,
201.34228187919464: A4^201.34228187919464,
201.34228187919464: B4/201.34228187919464 + E5~201.34228187919464,
201.34228187919464: C4-201.34228187919464,
201.34228187919464: C5^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: A4^201.34228187919464,
201.34228187919464: A4~201.34228187919464,
201.34228187919464: G4/201.34228187919464 + C4-201.34228187919464 + C5~201.34228187919464,
201.34228187919464: F4^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: F4~201.34228187919464,
201.34228187919464: C4-201.34228187919464,
201.34228187919464: D4/201.34228187919464 + G4~201.34228187919464,
201.34228187919464: E4^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: D4~201.34228187919464,
201.34228187919464: C4/201.34228187919464,
201.34228187919464: E4/201.34228187919464 + C4-201.34228187919464 + A4~201.34228187919464,
201.34228187919464: F4^201.34228187919464 + C4-201.34228187919464,
201.34228187919464: E4~201.34228187919464`
  
const playback = playTune(ogMusic, Infinity)

  const DEAD = tune`
177.5147928994083,
44.37869822485207: E5/44.37869822485207 + D5/44.37869822485207 + C5/44.37869822485207 + B4/44.37869822485207 + F5/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + A4/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + A4/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + A4/44.37869822485207,
44.37869822485207: B4/44.37869822485207 + C5/44.37869822485207 + D5/44.37869822485207 + E5/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + G4/44.37869822485207,
44.37869822485207: G4/44.37869822485207 + F5/44.37869822485207,
44.37869822485207: A4/44.37869822485207 + B4/44.37869822485207 + C5/44.37869822485207 + D5/44.37869822485207 + E5/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + G4/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + G4/44.37869822485207,
44.37869822485207,
44.37869822485207: F5/44.37869822485207 + E5/44.37869822485207 + D5/44.37869822485207 + C5/44.37869822485207 + B4/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + C5/44.37869822485207 + A4/44.37869822485207,
44.37869822485207: F5/44.37869822485207 + C5/44.37869822485207 + A4/44.37869822485207,
621.301775147929`

const winner = tune `
198.67549668874173,
198.67549668874173: A5^198.67549668874173 + B4^198.67549668874173,
198.67549668874173: E5^198.67549668874173 + F4^198.67549668874173,
198.67549668874173: D5~198.67549668874173 + E4~198.67549668874173,
198.67549668874173,
198.67549668874173: F5~198.67549668874173 + G4~198.67549668874173,
198.67549668874173: G5^198.67549668874173 + A4^198.67549668874173,
198.67549668874173: A5^198.67549668874173 + B4^198.67549668874173,
198.67549668874173: F5~198.67549668874173 + G4~198.67549668874173,
198.67549668874173: A5^198.67549668874173 + B4^198.67549668874173,
198.67549668874173: G5^198.67549668874173 + A4^198.67549668874173,
198.67549668874173,
198.67549668874173: G5^198.67549668874173 + A4^198.67549668874173 + D4~198.67549668874173 + C5~198.67549668874173,
397.35099337748346,
198.67549668874173: G4~198.67549668874173 + F5~198.67549668874173,
198.67549668874173: G5^198.67549668874173 + A4^198.67549668874173,
198.67549668874173,
198.67549668874173: C5~198.67549668874173 + D4~198.67549668874173,
198.67549668874173: D5^198.67549668874173,
198.67549668874173: E5^198.67549668874173 + E4^198.67549668874173,
198.67549668874173,
198.67549668874173: G5^198.67549668874173 + A4^198.67549668874173,
198.67549668874173: E5~198.67549668874173 + F4~198.67549668874173,
198.67549668874173: G5^198.67549668874173 + A4^198.67549668874173,
198.67549668874173,
198.67549668874173: C5^198.67549668874173,
198.67549668874173: A4~198.67549668874173,
198.67549668874173: F4~198.67549668874173,
198.67549668874173: F4~198.67549668874173,
397.35099337748346`


afterInput(() => {
  
    const trapsCovered = tilesWith(player, enemy); 
    
    if (trapsCovered.length > 0) {
      playTune(DEAD, 1)
        setMap(levels[level])
    }
})


afterInput(() => {
  
  const targetNumber = tilesWith(goal).length;
  const numberCovered = tilesWith(goal, player).length;

  if (numberCovered === targetNumber) {
    level = level + 1;
    const currentLevel = levels[level];
    clearText()
    if (currentLevel !== undefined) {
      setMap(currentLevel);
    } else {
     
      playback.end(ogMusic)
      playTune(winner, 1)
      addText("you win!!!!! :D", { y: 6, color: color`5` });
    }
  }
});

if (level==0){
addText("dog:(p1)",{x:12,y: 1, color: color `6`})
  addText("cat:(p2)",{x:1,y: 1, color: color `3`})
  addText("get the dog!",{x:1,y: 10, color: color `3`})
  addText(" W up",{x:13,y: 2, color: color `6`})
 addText(" A left",{x:13,y: 3, color: color `6`})
 addText(" S down",{x:13,y: 4, color: color `6`})
  addText(" D right",{x:12,y: 5, color: color `6`})
    addText(" I up",{x:1,y: 2, color: color `3`})
 addText(" J left",{x:1,y: 3, color: color `3`})
 addText(" K down",{x:1,y: 4, color: color `3`})
  addText(" a right",{x:1,y: 5, color: color `3`})
  addText("get the gift!", {x:7,y:12, color: color`6`})
  addText("MUST BE PLAYED", {x:1,y:13, color: color`0`})
  addText(" WITH TWO PLAYERS", {x:1,y:14, color: color`0`})
}



  
